package com.hlt.shuiliting.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hlt.shuiliting.dao.GongChengXMDAO;
import com.hlt.shuiliting.valuebean.GongChengXMBean;

public class GongChengXMServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public GongChengXMServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");//�������Ĳ���
		response.setCharacterEncoding("UTF-8");//�������Ĳ���
		response.setContentType("text/html");
		
		String servletPath = request.getServletPath();
		if (servletPath.equalsIgnoreCase("/listGongCheng")) {
			listGongCheng(request, response);
		} else if (servletPath.equalsIgnoreCase("/insertGongCheng")) {
			insertGongCheng(request, response);
		} else if (servletPath.equalsIgnoreCase("/viewGongCheng")) {
			viewGongCheng(request, response);
		} else if (servletPath.equalsIgnoreCase("/queryGongCheng")) {
			queryGongCheng(request, response);
		} else if (servletPath.equalsIgnoreCase("/deleteGongCheng")) {
			deleteGongCheng(request, response);
		} else if (servletPath.equalsIgnoreCase("/updateGongCheng")) {
			updateGongCheng(request, response);
		}
		
	}
	
	public void listGongCheng(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List list = null;
		String pageSize = request.getParameter("pageSize");
		String pageNum = request.getParameter("pageNum");
		GongChengXMDAO gongChengXMDAO = new GongChengXMDAO();
		
		list = gongChengXMDAO.list((Integer.parseInt(pageSize)), (Integer.parseInt(pageNum)));
		String pageCount = Integer.toString(gongChengXMDAO.getPageCount());
		
		request.setAttribute("pageCount", pageCount);
		request.setAttribute("pageNum", pageNum);
		request.setAttribute("gongChengList", list);
		
		request.getRequestDispatcher("/GongChengXM_List.jsp").forward(request, response);
	}
	
	public void insertGongCheng(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GongChengXMDAO gongChengXMDAO = new GongChengXMDAO();
		GongChengXMBean gongChengXMBean = new GongChengXMBean();
		String ZhuangTai = request.getParameter("ZhuangTai");
		String JiLuSJ = request.getParameter("JiLuSJ");
		String LuRuR = request.getParameter("LuRuR");
		String XiangMuDM = request.getParameter("XiangMuDM");
		String XiangMuMC = request.getParameter("XiangMuMC");
		String GongChengLB = request.getParameter("GongChengLB");
		String XiangMuFRMC = request.getParameter("XiangMuFRMC");
		String XiangMuSD = request.getParameter("XiangMuSD");
		String XiangMuZGBM = request.getParameter("XiangMuZGBM");
		String GongChengGM = request.getParameter("GongChengGM");
		String GongChengZTZ = request.getParameter("GongChengZTZ");
		String JiHuaKGRQ = request.getParameter("JiHuaKGRQ");
		String JiHuaJGRQ = request.getParameter("JiHuaJGRQ");
		String XiangMuJSDW = request.getParameter("XiangMuJSDW");
		String XiangMuFZRXM = request.getParameter("XiangMuFZRXM");
		String JiShuFZRXM = request.getParameter("JiShuFZRXM");
		String ShiJiKGRQ = request.getParameter("ShiJiKGRQ");
		String ShiJiJGRQ = request.getParameter("ShiJiJGRQ");
		String DiFangZFFZR = request.getParameter("DiFangZFFZR");
		String ZhuGuanBMFZR = request.getParameter("ZhuGuanBMFZR");
		String JianSheDWFZR = request.getParameter("JianSheDWFZR");
		String FaRenPZWH = request.getParameter("FaRenPZWH");
		String FaRenDB = request.getParameter("FaRenDB");
		String FaRenJSFZR = request.getParameter("FaRenJSFZR");
		String FaRenXCGLY = request.getParameter("FaRenXCGLY");
		String LaiYuanLX = request.getParameter("LaiYuanLX");
		String XiangMuTZQY = request.getParameter("XiangMuTZQY");
		String ZhongYangZJ = request.getParameter("ZhongYangZJ");
		String ShengPeiT = request.getParameter("ShengPeiT");
		String ShiPeiT = request.getParameter("ShiPeiT");
		String XianPeiT = request.getParameter("XianPeiT");
		String TouziFZJ = request.getParameter("TouziFZJ");
		String LeiJiDWZYZJ = request.getParameter("LeiJiDWZYZJ");
		String LeiJiDWSPT = request.getParameter("LeiJiDWSPT");
		String LeiJiDWShiPT = request.getParameter("LeiJiDWShiPT");
		String LeiJiDWXPT = request.getParameter("LeiJiDWXPT");
		String LeiJiDWTZZJ = request.getParameter("LeiJiDWTZZJ");
		String JianSheYDPZS = request.getParameter("JianSheYDPZS");
		String GuoYouTDGHDS = request.getParameter("GuoYouTDGHDS");
		String GuoYouTDSYZ = request.getParameter("GuoYouTDSYZ");
		String JianSheNRJJ = request.getParameter("JianSheNRJJ");
		
		gongChengXMBean.setZhuangTai(ZhuangTai);
		gongChengXMBean.setJiLuSJ(JiLuSJ);
		gongChengXMBean.setLuRuR(LuRuR);
		gongChengXMBean.setXiangMuDM(XiangMuDM);
		gongChengXMBean.setXiangMuMC(XiangMuMC);
		gongChengXMBean.setGongChengLB(GongChengLB);
		gongChengXMBean.setXiangMuFRMC(XiangMuFRMC);
		gongChengXMBean.setXiangMuSD(XiangMuSD);
		gongChengXMBean.setXiangMuZGBM(XiangMuZGBM);
		gongChengXMBean.setGongChengGM(GongChengGM);
		gongChengXMBean.setGongChengZTZ(GongChengZTZ);
		gongChengXMBean.setJiHuaKGRQ(JiHuaKGRQ);
		gongChengXMBean.setJiHuaJGRQ(JiHuaJGRQ);
		gongChengXMBean.setXiangMuJSDW(XiangMuJSDW);
		gongChengXMBean.setXiangMuFZRXM(XiangMuFZRXM);
		gongChengXMBean.setJiShuFZRXM(JiShuFZRXM);
		gongChengXMBean.setShiJiKGRQ(ShiJiKGRQ);
		gongChengXMBean.setShiJiJGRQ(ShiJiJGRQ);
		gongChengXMBean.setDiFangZFFZR(DiFangZFFZR);
		gongChengXMBean.setZhuGuanBMFZR(ZhuGuanBMFZR);
		gongChengXMBean.setJianSheDWFZR(JianSheDWFZR);
		gongChengXMBean.setFaRenPZWH(FaRenPZWH);
		gongChengXMBean.setFaRenDB(FaRenDB);
		gongChengXMBean.setFaRenJSFZR(FaRenJSFZR);
		gongChengXMBean.setFaRenXCGLY(FaRenXCGLY);
		gongChengXMBean.setLaiYuanLX(LaiYuanLX);
		gongChengXMBean.setXiangMuTZQY(XiangMuTZQY);
		gongChengXMBean.setZhongYangZJ(ZhongYangZJ);
		gongChengXMBean.setShengPeiT(ShengPeiT);
		gongChengXMBean.setShiPeiT(ShiPeiT);
		gongChengXMBean.setXianPeiT(XianPeiT);
		gongChengXMBean.setTouziFZJ(TouziFZJ);
		gongChengXMBean.setLeiJiDWZYZJ(LeiJiDWZYZJ);
		gongChengXMBean.setLeiJiDWSPT(LeiJiDWSPT);
		gongChengXMBean.setLeiJiDWShiPT(LeiJiDWShiPT);
		gongChengXMBean.setLeiJiDWXPT(LeiJiDWXPT);
		gongChengXMBean.setLeiJiDWTZZJ(LeiJiDWTZZJ);
		gongChengXMBean.setJianSheYDPZS(JianSheYDPZS);
		gongChengXMBean.setGuoYouTDGHDS(GuoYouTDGHDS);
		gongChengXMBean.setGuoYouTDSYZ(GuoYouTDSYZ);
		gongChengXMBean.setJianSheNRJJ(JianSheNRJJ);
		
		gongChengXMDAO.insert(gongChengXMBean);
		response.sendRedirect("listGongCheng");
	}
	
	public void viewGongCheng(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GongChengXMDAO gongChengXMDAO = new GongChengXMDAO();
		String id = request.getParameter("id");
		String viewOrUpdate = request.getParameter("viewOrUpdate");
		Map map = gongChengXMDAO.view(Integer.parseInt(id));
		request.setAttribute("gongCheng", map);
		if (viewOrUpdate.equalsIgnoreCase("update")) {
			request.getRequestDispatcher("/GongChengXM_Update.jsp").forward(request, response);
		} else {
			request.getRequestDispatcher("/GongChengXM_View.jsp").forward(request, response);
		}
	}
	
	public void queryGongCheng(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GongChengXMDAO gongChengXMDAO = new GongChengXMDAO();
		String XiangMuDM = request.getParameter("XiangMuDM");
		String XiangMuMC = request.getParameter("XiangMuMC");
		String GongChengLB = request.getParameter("GongChengLB");
		String XiangMuSD = request.getParameter("XiangMuSD");
		String XiangMuJSDW = request.getParameter("XiangMuJSDW");
		List list = gongChengXMDAO.list(XiangMuDM, XiangMuMC, GongChengLB, XiangMuSD, XiangMuJSDW);
		request.setAttribute("gongChengList", list);
		request.getRequestDispatcher("/GongChengXM_List.jsp").forward(request, response);
	}
	
	public void deleteGongCheng(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GongChengXMDAO gongChengXMDAO = new GongChengXMDAO();
		String ID = request.getParameter("ID");
		
		int updateCount = gongChengXMDAO.delete(Integer.parseInt(ID));
		response.sendRedirect("listGongCheng");
	}
	
	public void updateGongCheng(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GongChengXMDAO gongChengXMDAO = new GongChengXMDAO();
		GongChengXMBean gongChengXMBean = new GongChengXMBean();
		String ID = request.getParameter("ID");
		String ZhuangTai = request.getParameter("ZhuangTai");
		String JiLuSJ = request.getParameter("JiLuSJ");
		String LuRuR = request.getParameter("LuRuR");
		String XiangMuDM = request.getParameter("XiangMuDM");
		String XiangMuMC = request.getParameter("XiangMuMC");
		String GongChengLB = request.getParameter("GongChengLB");
		String XiangMuFRMC = request.getParameter("XiangMuFRMC");
		String XiangMuSD = request.getParameter("XiangMuSD");
		String XiangMuZGBM = request.getParameter("XiangMuZGBM");
		String GongChengGM = request.getParameter("GongChengGM");
		String GongChengZTZ = request.getParameter("GongChengZTZ");
		String JiHuaKGRQ = request.getParameter("JiHuaKGRQ");
		String JiHuaJGRQ = request.getParameter("JiHuaJGRQ");
		String XiangMuJSDW = request.getParameter("XiangMuJSDW");
		String XiangMuFZRXM = request.getParameter("XiangMuFZRXM");
		String JiShuFZRXM = request.getParameter("JiShuFZRXM");
		String ShiJiKGRQ = request.getParameter("ShiJiKGRQ");
		String ShiJiJGRQ = request.getParameter("ShiJiJGRQ");
		String DiFangZFFZR = request.getParameter("DiFangZFFZR");
		String ZhuGuanBMFZR = request.getParameter("ZhuGuanBMFZR");
		String JianSheDWFZR = request.getParameter("JianSheDWFZR");
		String FaRenPZWH = request.getParameter("FaRenPZWH");
		String FaRenDB = request.getParameter("FaRenDB");
		String FaRenJSFZR = request.getParameter("FaRenJSFZR");
		String FaRenXCGLY = request.getParameter("FaRenXCGLY");
		String LaiYuanLX = request.getParameter("LaiYuanLX");
		String XiangMuTZQY = request.getParameter("XiangMuTZQY");
		String ZhongYangZJ = request.getParameter("ZhongYangZJ");
		String ShengPeiT = request.getParameter("ShengPeiT");
		String ShiPeiT = request.getParameter("ShiPeiT");
		String XianPeiT = request.getParameter("XianPeiT");
		String TouziFZJ = request.getParameter("TouziFZJ");
		String LeiJiDWZYZJ = request.getParameter("LeiJiDWZYZJ");
		String LeiJiDWSPT = request.getParameter("LeiJiDWSPT");
		String LeiJiDWShiPT = request.getParameter("LeiJiDWShiPT");
		String LeiJiDWXPT = request.getParameter("LeiJiDWXPT");
		String LeiJiDWTZZJ = request.getParameter("LeiJiDWTZZJ");
		String JianSheYDPZS = request.getParameter("JianSheYDPZS");
		String GuoYouTDGHDS = request.getParameter("GuoYouTDGHDS");
		String GuoYouTDSYZ = request.getParameter("GuoYouTDSYZ");
		String JianSheNRJJ = request.getParameter("JianSheNRJJ");
		
		gongChengXMBean.setID(Integer.parseInt(ID));
		gongChengXMBean.setZhuangTai(ZhuangTai);
		gongChengXMBean.setJiLuSJ(JiLuSJ);
		gongChengXMBean.setLuRuR(LuRuR);
		gongChengXMBean.setXiangMuDM(XiangMuDM);
		gongChengXMBean.setXiangMuMC(XiangMuMC);
		gongChengXMBean.setGongChengLB(GongChengLB);
		gongChengXMBean.setXiangMuFRMC(XiangMuFRMC);
		gongChengXMBean.setXiangMuSD(XiangMuSD);
		gongChengXMBean.setXiangMuZGBM(XiangMuZGBM);
		gongChengXMBean.setGongChengGM(GongChengGM);
		gongChengXMBean.setGongChengZTZ(GongChengZTZ);
		gongChengXMBean.setJiHuaKGRQ(JiHuaKGRQ);
		gongChengXMBean.setJiHuaJGRQ(JiHuaJGRQ);
		gongChengXMBean.setXiangMuJSDW(XiangMuJSDW);
		gongChengXMBean.setXiangMuFZRXM(XiangMuFZRXM);
		gongChengXMBean.setJiShuFZRXM(JiShuFZRXM);
		gongChengXMBean.setShiJiKGRQ(ShiJiKGRQ);
		gongChengXMBean.setShiJiJGRQ(ShiJiJGRQ);
		gongChengXMBean.setDiFangZFFZR(DiFangZFFZR);
		gongChengXMBean.setZhuGuanBMFZR(ZhuGuanBMFZR);
		gongChengXMBean.setJianSheDWFZR(JianSheDWFZR);
		gongChengXMBean.setFaRenPZWH(FaRenPZWH);
		gongChengXMBean.setFaRenDB(FaRenDB);
		gongChengXMBean.setFaRenJSFZR(FaRenJSFZR);
		gongChengXMBean.setFaRenXCGLY(FaRenXCGLY);
		gongChengXMBean.setLaiYuanLX(LaiYuanLX);
		gongChengXMBean.setXiangMuTZQY(XiangMuTZQY);
		gongChengXMBean.setZhongYangZJ(ZhongYangZJ);
		gongChengXMBean.setShengPeiT(ShengPeiT);
		gongChengXMBean.setShiPeiT(ShiPeiT);
		gongChengXMBean.setXianPeiT(XianPeiT);
		gongChengXMBean.setTouziFZJ(TouziFZJ);
		gongChengXMBean.setLeiJiDWZYZJ(LeiJiDWZYZJ);
		gongChengXMBean.setLeiJiDWSPT(LeiJiDWSPT);
		gongChengXMBean.setLeiJiDWShiPT(LeiJiDWShiPT);
		gongChengXMBean.setLeiJiDWXPT(LeiJiDWXPT);
		gongChengXMBean.setLeiJiDWTZZJ(LeiJiDWTZZJ);
		gongChengXMBean.setJianSheYDPZS(JianSheYDPZS);
		gongChengXMBean.setGuoYouTDGHDS(GuoYouTDGHDS);
		gongChengXMBean.setGuoYouTDSYZ(GuoYouTDSYZ);
		gongChengXMBean.setJianSheNRJJ(JianSheNRJJ);
		
		gongChengXMDAO.update(gongChengXMBean);
		response.sendRedirect("listGongCheng");
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
